from flask import Blueprint, render_template, redirect, url_for, flash, jsonify
from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user
from flask_login import current_user
from python.model.model import Attraction
main_bp = Blueprint('main', __name__)
menu_bp = Blueprint('menu', __name__, url_prefix='/menu')

@main_bp.route('/')
@login_required
def index():
    # 根据用户类型渲染不同的模板
    if current_user.is_admin:
        return render_template('index2.html', username=current_user.username)
    else:
        return render_template('index.html', username=current_user.username)
@menu_bp.route('/seach_data')
def seach_data():
    return render_template('menu/seach_data.html')


@menu_bp.route('/finall')
def big_title():
    return render_template('menu/finall.html')

@menu_bp.route('/map_sales')
def map_sales():
    return render_template('menu/map_sales.html')

@menu_bp.route('/bar_sales')
def bar_sales():
    return render_template('menu/bar_sales.html')

@menu_bp.route('/bar_star')
def bar_star():
    return render_template('menu/bar_4A-5A.html')


@menu_bp.route('/map_star')
def map_star():
    return render_template('menu/map_4A-5A.html')

@menu_bp.route('/sales')
def sales():
    return render_template('menu/sales.html')


@menu_bp.route('/pie_price')
def pie_price():
    return render_template('menu/pie_price.html')

@menu_bp.route('/rose_star')
def rose_star():
    return render_template('menu/rose_4A-5A.html')


@menu_bp.route('/scatter_price')
def scatter_price():
    return render_template('menu/scatter_price.html')

@menu_bp.route('/scatter_star')
def scatter_star():
    return render_template('menu/scatter_4A-5A.html')

@menu_bp.route('/wordcloud')
def wordcloud():
    return render_template('menu/wordcloud.html')

@menu_bp.route('/logout', methods=['GET'])
def logout():
    logout_user()  # 清除用户会话
    return redirect(url_for('auth.login'))  # 重定向到登录页面
